import encryption from '@/libs/encryption.js'
import {boardlist_new } from '@/api/boardcast_new'
import { log } from 'three';

export default {
    namespaced: true,
    state: {
        needRefreshUserList: '', // 数据变更时，需要刷新用户列表
        boardLists:[],
        notReadBoardList:[],
        boardCount:0, //总数
        notReadCount:0, //未读数
        newNotice:{},
        chatNotice:{},
        notReadChatCount:0,
        classNotReadChatCount:0,
        clearNotice:'',
        refreshTime: 0,
    },
    getters:{
        getBoardLists:(state)=>{
            return state.boardLists;
        },
        getBoardCount:(state)=>{
            return state.boardCount;
        },
        getBoardLookStatus:(state) => {
            return state.lookStatus;
        }
    },
    mutations: {
        setRefreshTime(state) {
            state.refreshTime = (new Date()).getTime()
            console.log(state.refreshTime, 111);
          },
        setRefresTimestamp(state) { // 自行设置一个时间戳即可，不需要传参
            state.needRefreshUserList = (new Date()).getTime()
        },
        setBoardLists(state,obj){
            state.boardLists = obj;
        },
        setBoardCount(state,count){
            state.boardCount = count
        },
        setNotReadCount(state,count){
            state.notReadCount = count;
        },
        setNewNotice(state,content23){
            state.newNotice = content23;
        },
        setNotReadBoardList(state,list){
            state.notReadBoardList = list;
        },
        setChatNotice(state,content23){
            state.chatNotice = content23;
        },
        setNotReadChat(state,num){
            state.notReadChatCount = num;
        },
        setClassNotReadChat(state,num){ //班级聊天使用
            state.classNotReadChatCount = num;
        },
        setClearNotice(state,msg){ //场景聊天使用
            state.clearNotice = msg;
        },
    },
    actions: {
        //获取未读board
        getBoardListNotRead({ commit, state }){
            let October = sessionStorage.getItem('November')
            October = JSON.parse(encryption.SelfUseDecrypt(October))
            let USER_ID = October.userId
            //查询未读数
            let params = {
                pageIndex:1,
                pageSize:1,
                lookStatus:0,
                receiver:USER_ID
            }
            boardlist_new(params).then(data=>{
                if(data.code==1){
                    commit('setNotReadCount',data.data.total);
                }
            })
        }
    }
}
